@namespace SwashbucklerDiary.Rcl.Components
@inherits DialogComponentBase

<MultiDisplay>
    <MobileContent>
        <CustomMBottomSheet MyValue="Visible"
                            MyValueChanged="InternalVisibleChanged"
                            ContentClass="rounded-t-lg">
            @GenCard(GenMobileCardActionsContent())
        </CustomMBottomSheet>
    </MobileContent>
    <DesktopContent>
        <CustomMDialog MyValue="Visible"
                       MyValueChanged="InternalVisibleChanged"
                       ContentClass="rounded-lg"
                       MaxWidth="420">
            @GenCard(GenDesktopCardActionsContent())
        </CustomMDialog>
    </DesktopContent>
</MultiDisplay>

<MultiDatePicker @bind-Visible="showMinDate"
                 @bind-Value="MinDate"
                 Max="MaxDate">
</MultiDatePicker>

<MultiDatePicker @bind-Visible="showMaxDate"
                 @bind-Value="MaxDate"
                 Min="MinDate">
</MultiDatePicker>

@code {
    private RenderFragment GenCard(RenderFragment cardActionsContent) => __builder =>
    {
        <MCard Class="rounded-t-lg">
            <MCardTitle Class="font-weight-bold flex-nowrap">
                <wc-auto-scroll-text>@(I18n.T("Filter"))</wc-auto-scroll-text>
                <MSpacer></MSpacer>
                <MButton Icon="true"
                         OnClick="HandleOnCancel">
                    <MIcon>close</MIcon>
                </MButton>
            </MCardTitle>
            <MCardText Class="pb-0">
                <div>
                    <MChipGroup @bind-Value="DefaultDate"
                                Column="true">
                        @foreach (var item in DefaultDates)
                        {
                            <MChip @key="item.Key"
                                   Value="item.Key"
                                   Class="flex-grow-1 justify-center"
                                   Filter="true"
                                   OnClick="SelectDeafultDate">
                                @(I18n.T(item.Key))
                            </MChip>
                        }

                    </MChipGroup>
                    <MChipGroup Column="true"
                                Multiple="true">
                        <MChip Class="flex-grow-1 justify-center mx-0"
                               IsActive="false"
                               OnClick="OpenMinDateDialog">
                            @MinDateText
                        </MChip>
                        <div class="d-flex align-center">
                            <MIcon Small>
                                remove
                            </MIcon>
                        </div>
                        <MChip Class="flex-grow-1 justify-center"
                               IsActive="false"
                               OnClick="OpenMaxDateDialog">
                            @MaxDateText
                        </MChip>
                    </MChipGroup>
                </div>
            </MCardText>
            <MCardActions>
                @cardActionsContent
            </MCardActions>
        </MCard>
    };

    private RenderFragment GenMobileCardActionsContent() => __builder =>
    {
        <MButton Class="text-subtitle-1 flex-grow-1 mb-2"
                 Style="flex-basis:0;"
                 Rounded="true"
                 Depressed="true"
                 Large="true"
                 Color="rgba(var(--m-theme-surface-container-high))"
                 OnClick="HandleOnReset">
            <wc-auto-scroll-text class="justify-center">@(I18n.T("Reset"))</wc-auto-scroll-text>
        </MButton>
        <MButton Class="text-subtitle-1 flex-grow-1 mb-2"
                 Style="flex-basis:0;"
                 Rounded="true"
                 Depressed="true"
                 Large="true"
                 Color="rgba(var(--m-theme-surface-container-high))"
                 OnClick="HandleOnOK">
            <wc-auto-scroll-text class="justify-center">@(I18n.T("OK"))</wc-auto-scroll-text>
        </MButton>
    };

    private RenderFragment GenDesktopCardActionsContent() => __builder =>
    {
        <MSpacer></MSpacer>
        <MButton Text="true"
                 OnClick="HandleOnReset">
            @(I18n.T("Reset"))
        </MButton>
        <MButton Text="true"
                 Color="primary"
                 OnClick="HandleOnOK">
            @(I18n.T("OK"))
        </MButton>
    };
}
